package com.jerry.constellation.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.jerry.constellation.Adapter.GuideAdapter;
import com.jerry.constellation.R;

import java.util.ArrayList;
import java.util.List;

public class GuideActivity extends AppCompatActivity {

    private ViewPager viewPager;
    //存放id
    int resid[] = {
            R.mipmap.loading1,
            R.mipmap.loading2,
            R.mipmap.loading3,
    };
    List<ImageView> mData;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        viewPager = findViewById(R.id.guide_Vp);
        mData=new ArrayList<>();
        initViewPager();
        //为第三个图片设置事件监听
        setListerner();
    }

    private void setListerner() {
        int size = mData.size();
        ImageView imageView = mData.get(size-1);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(GuideActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }

    private void initViewPager() {
        for (int i = 0; i < resid.length; i++) {
            ImageView imageView = new ImageView(this);
            imageView.setImageResource(resid[i]);
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            imageView.setLayoutParams(lp);
            mData.add(imageView);
        }
        GuideAdapter adapter = new GuideAdapter(mData);
        //设置适配器
        viewPager.setAdapter(adapter);

    }
}